package tools;
import feffects.easing.Bounce;
import feffects.Tween;
import haxe.Timer;
import js.Lib;

/**
 * ...
 * @author PRASS
 */

class ASprite 
{

	public var dom : JQuery;
	public var domID : String;
	
	private var _height : Float;
	private var _width	: Float;
	private var _x		: Int;
	private var _y		: Int;
	private var _alpha	: Float;
	
	private var _tween	: Tween;
	
	public function new( pDom : JQuery, id : String = "" ) 
	{
		domID = id;
		dom = pDom;
	}
	
	/* Height */
	public function getHeight() : Float
	{
		return _height;
	}
	
	public function setHeight( value : Float ) : Void
	{
		_height = value;
		dom.css("height", value + "px");
	}
	
	/* Width */
	public function getWidth() : Float
	{
		return _width;
	}
	
	public function setWidth( value : Float ) : Void
	{
		_width = value;
		dom.css("width", value + "px");
	}
	
	/* X */
	public function getX () : Int
	{
		return _x;
	}
	
	public function setX ( value : Int ) : Void
	{
		_x = value;
		dom.css("left", value + "px");
	}
	
	/* Y */
	public function getY () : Int
	{
		return _y;
	}
	
	public function setY ( value : Int ) : Void
	{
		_y = value;
		dom.css("top", value + "px");
	}
	
	/* Alpha */
	public function getAlpha () : Float
	{
		return _alpha;
	}
	
	public function setAlpha ( value : Float ) : Void
	{
		_alpha = value;
		dom.css("opacity", _alpha);
	}
	
	/* Visible */
	public function visible ( value : Bool ) : Void
	{
		if (value)
			dom.css("display", "block");
		else
			dom.css("display", "none");
	}
	
	/* Tween */
	public function tween ( init : Float, prop : Dynamic, value : Float, time : Int, ease : Easing, ?callBack : Dynamic , delay : Int = 0 ) : Void
	{
		if (_tween != null) _tween.stop();
		
		_tween = new Tween( init, value, time, null, null, ease);
		_tween.setTweenHandlers( prop, callBack );
		Timer.delay( _tween.start, delay);
	}
	
	//private var _toTween	: Array<Dynamic>;
	//private var _callBack	: Dynamic;
	//private var _tweens		: Array<Tween>;
	//private var _appliers	: Array<Dynamic>;
	
	public function tweens( props : Array<Dynamic>, duration : Int, ease : Easing, ?callBack : Dynamic , delay : Int = 0 ) : Void
	{
		//if (callBack != null ) _callBack = callBack;
		
		/*if (_appliers == null)
		{
			_appliers = new Array<Dynamic>();
			_appliers.push( applier1 );
			_appliers.push( applier2 );
			_appliers.push( applier3 );
		}*/
		
		//_toTween = new Array<Dynamic>();
		
		var i : Int = 0;
		var tween : Tween;
		
		while (i < props.length)
		{
			
			
			//var getset : Array<Dynamic> = _selectProperty( props[i].prop );
			
			/*Lib.alert(getset[0]);
			Lib.alert(getset[1]);*/
			
			_tween = new Tween( props[i].init, props[i].value, duration, null, null, ease);
			//_toTween[i] = props[i].prop;
			
			if (i == props.length-1)
				_tween.setTweenHandlers( props[i].prop, callBack );
			else
				_tween.setTweenHandlers( props[i].prop);
			
			Timer.delay( _tween.start, delay);
			
			i++;
		}
		
		//Lib.alert(_toTween.length);
		
	}
	
	/*private function _selectProperty( prop : String ) : Array<Dynamic>
	{
		var array : Array<Dynamic> = new Array<Dynamic>();
		
		switch( prop )
		{
			case "alpha": 	array = [ _tgt.getAlpha, _tgt.setAlpha ];
			case "x":	 	array = [ _tgt.getX, _tgt.setX ];
			case "y": 		array = [ _tgt.getY, _tgt.setY ];
			case "width": 	array = [ _tgt.getWidth, _tgt.setWidth ];
			case "height": 	array = [ _tgt.getHeight, _tgt.setHeight ];
		}
		
		return array;
	}*/
	
	/*private function applier1 ( v : Float ) : Void
	{
		_toTween[0](v);
	}
	
	private function applier2 ( v : Float ) : Void
	{
		_toTween[1](v);
	}
	
	private function applier3 ( v : Float ) : Void
	{
		_toTween[2](v);
	}

	private function clearTweens(v:Float=0) : Void
	{
		if(_callBack != null ) _callBack();
	}
	
	private function _empty() : Void {}*/
	
}